package com.yungu.swift.api.route.v2.passenger;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yungu.swift.api.base.gateway.CurrentUser;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.model.api.ApiBusinessParam;
import com.yungu.swift.base.model.api.ApiParam;
import com.yungu.swift.common.model.dto.CommonArticleDto;
import com.yungu.swift.common.model.dto.CommonTagDto;
import com.yungu.swift.common.service.CommonArticleService;
import com.yungu.swift.common.service.CommonTagService;
import com.yungu.swift.constants.CommonConstant;
import com.yungu.swift.constants.MagicConstant;
import com.yungu.swift.utils.MapUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 乘客标签接口
 *
 * @author : cuixiuyin
 * @date : 2019/12/9
 */
@RestController
@RequestMapping("/api/v2/passenger/tag")
@Api(value = "【乘客】【标签】通用标签接口V2", tags = "V2-通用标签接口")
public class PasTagApi {

    @Reference
    private CommonTagService commonTagService;
    @Reference
    private CommonArticleService commonArticleService;

    @RequestMapping(value = {"/evaluate"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(value = "获取评价标签", notes = "评价标签")
    public ResponseData<List<CommonTagDto>> evaluateTag(@CurrentUser ApiParam apiParam) {
        Map<String, Object> paramMap = MapUtils.build(8);
        //乘客
        paramMap.put("identity", CommonConstant.PASSENGER);
        paramMap.put("tagType", CommonConstant.TAG_TYPE_EVALUATE);
        paramMap.put("tagStatus", MagicConstant.INT_ONE);
        paramMap.put("appid", apiParam.getAppid());
        return commonTagService.list(paramMap);
    }

    @RequestMapping(value = {"/complain"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(value = "获取投诉标签", notes = "投诉标签")
    public ResponseData<List<CommonTagDto>> complainTag(@CurrentUser ApiParam apiParam) {
        Map<String, Object> paramMap = MapUtils.build(8);
        paramMap.put("identity", CommonConstant.PASSENGER);
        paramMap.put("tagType", CommonConstant.TAG_TYPE_COMPLAIN);
        paramMap.put("tagStatus", MagicConstant.INT_ONE);
        paramMap.put("appid", apiParam.getAppid());
        return commonTagService.list(paramMap);
    }

    @PostMapping(value = {"/takemsg"})
    @ApiOperation(value = "获取捎话标签", notes = "捎话标签")
    public ResponseData<List<CommonTagDto>> takemsgTag(@RequestHeader String appid,
                                                       @RequestBody ApiBusinessParam businessParam) {
        Map<String, Object> paramMap = MapUtils.build(8);
        paramMap.put("identity", CommonConstant.PASSENGER);
        paramMap.put("tagType", CommonConstant.TAG_TYPE_SEND_ORAL);
        paramMap.put("tagStatus", MagicConstant.INT_ONE);
        paramMap.put("appid", appid);
        paramMap.put("businessType", businessParam.getBusinessType());
        return commonTagService.list(paramMap);
    }

    @RequestMapping(value = {"/cancelMsg"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(value = "获取取消原因标签", notes = "取消原因标签")
    public ResponseData<List<CommonTagDto>> listOfCancelMsg(@RequestHeader String appid,
                                                            @CurrentUser ApiParam apiParam) {
        Map<String, Object> paramMap = MapUtils.build(8);
        paramMap.put("tagType", CommonConstant.TAG_TYPE_CANCEL);
        paramMap.put("tagStatus", MagicConstant.INT_ONE);
        paramMap.put("identity", CommonConstant.PASSENGER);
        paramMap.put("appid", appid);
        return commonTagService.list(paramMap);
    }

    @RequestMapping(value = {"/problem"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(value = "获取常见问题", notes = "获取常见问题")
    public ResponseData<List<CommonArticleDto>> problemTag(@RequestHeader String appid,
                                                           @CurrentUser ApiParam apiParam) {
        Map<String, Object> paramMap = MapUtils.build(4);
        paramMap.put("appid", appid);
        paramMap.put("articleType", CommonConstant.PASSENGER);
        ResponseData<List<CommonArticleDto>> responseData = commonArticleService.list(paramMap);
        if (responseData.isSuccess() && CollectionUtils.isNotEmpty(responseData.getData())) {
            for (CommonArticleDto articleDto : responseData.getData()) {
                articleDto.setArticleSimpleContent(null);
                articleDto.setArticleContent(null);
            }
        }
        return responseData;
    }
}
